<?php

namespace app\api\logic\page;

use think\facade\Request;
use app\common\repository\user\R as UserRRepository;
use app\common\repository\book\R as BookRRepository;
use app\common\repository\link\R as LinkRRepository;
use app\common\repository\article\R as ArticleRRepository;
use app\common\repository\promote\R as PromoteRRepository;

class Article
{
    public function __construct(
        UserRRepository $userRRepository,
        BookRRepository $bookRRepository,
        LinkRRepository $linkRRepository,
        ArticleRRepository $articleRRepository,
        PromoteRRepository $promoteRRepository
    ) {
        $this->userRRepository = $userRRepository;
        $this->bookRRepository = $bookRRepository;
        $this->linkRRepository = $linkRRepository;
        $this->articleRRepository = $articleRRepository;
        $this->promoteRRepository = $promoteRRepository;
    }

    public function info()
    {
        $articleId = Request::param('id');
        if (!$articleId) {
            return ['done' => false, 'code' => config('code.common.paramsRequire')];
        }
        $user = $this->userRRepository->getUserByArticleId($articleId);
        $userHotArticles = $this->articleRRepository->getUserHotArticles($user->id);
        $userHotBooks = $this->bookRRepository->getUserHotBooks($user->id);
        $article = $this->articleRRepository->getArticle(['id' => $articleId]);
        $mostViewArticles = $this->articleRRepository->getMostViewArticles();
        $promotes = $this->promoteRRepository->getPromotes();
        $link =  $this->linkRRepository->getLinks();
        return ['data' => [
            'user' => $user,
            'userHotArticles' => $userHotArticles,
            'userHotBooks' => $userHotBooks,
            'article' => $article,
            'mostViewArticles' => $mostViewArticles,
            'promotes' => $promotes,
            'link' =>  $link
        ]];
    }
}
